package com.bestcem.xm.qdes.mq.receiver.biz.rabbit;

import com.alibaba.fastjson.JSONObject;
import com.bestcem.xm.qdes.mq.dto.StatusDto;
import com.bestcem.xm.qdes.mq.receiver.biz.QdesConsumers;
import com.bestcem.xm.qdes.mq.receiver.biz.ReceiverService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.stereotype.Component;

import java.util.function.Consumer;

@Slf4j
@Component
@ConditionalOnProperty(prefix = "application", name = "mqType", havingValue = "rabbit")
public class RabbitConsumers implements QdesConsumers {

    private final ReceiverService receiverService;

    public RabbitConsumers(ReceiverService receiverService) {
        this.receiverService = receiverService;
    }

    @Bean
    @Override
    public Consumer<GenericMessage<StatusDto>> projectUpdated() {
        return receiverService::projectUpdated;
    }

    @Bean
    @Override
    public Consumer<GenericMessage<JSONObject>> projectDeletedShare() {
        return receiverService::projectDeletedShare;
    }

    @Bean
    @Override
    public Consumer<GenericMessage<JSONObject>> saveQuestionColumn() {
        return receiverService::saveQuestionColumn;
    }
}
